home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / gnu / WinGnuPlot.lha / WinGnuPlot / Source / Commands.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-12  |  3.2 KB  |  141 lines

  1. #include "struct.c"
  2. #include "WinPlot.h"
  3.  
  4.        struct MsgPort *RexxReplyPort = NULL;
  5. static struct RexxMsg *OutRexxMsg = NULL;
  6. static        UBYTE   *CmdArgstring = NULL;
  7.  
  8. /* Init the ARexx Port */
  9. void _STI_250_OpenRexx(void)
  10. {
  11.  RexxReplyPort = CreateMsgPort();
  12.  OutRexxMsg = CreateRexxMsg(RexxReplyPort,NULL,"REXXPLOT");
  13. }
  14.  
  15. /* Close the ARexx Port */
  16. void _STD_250_CloseRexx(void)
  17. {
  18.  if (RexxReplyPort) DeleteMsgPort(RexxReplyPort);
  19.  if (OutRexxMsg) DeleteRexxMsg(OutRexxMsg);
  20. }
  21.  
  22. /* the Rexx command list */
  23. static struct List RexxList =
  24. {
  25.  (struct Node *)&RexxList.lh_Tail, NULL, (struct Node *)&RexxList.lh_Head
  26. };
  27.  
  28. static void SendFirst(void)
  29. {
  30.  struct MsgPort *TargetPort;
  31.  char           *Command = RexxList.lh_Head->ln_Name;
  32.  
  33.  if (CmdArgstring=CreateArgstring(Command,strlen(Command)))
  34.   {
  35.    OutRexxMsg->rm_Action=RXCOMM|RXFF_NOIO|RXFF_STRING;
  36.    OutRexxMsg->rm_Args[0]=(STRPTR)CmdArgstring;
  37.     
  38.    Forbid();
  39.    if (TargetPort=FindPort(RXSDIR))
  40.     PutMsg(TargetPort,&OutRexxMsg->rm_Node);
  41.    Permit();
  42.   }
  43. }
  44.  
  45. void SendRexxMsg(char *Command)
  46. {
  47.  struct Node    *RexxNode;
  48.  UBYTE          *QuotedCommand;
  49.  BOOL            Send;
  50.  
  51.  Send = RexxList.lh_Head->ln_Succ == NULL;
  52.  
  53.  QuotedCommand = malloc(strlen(Command)+3);
  54.  sprintf(QuotedCommand, "'%s'", Command);
  55.  RexxNode = malloc(sizeof(struct Node));
  56.  RexxNode->ln_Name = QuotedCommand;
  57.  AddTail(&RexxList, RexxNode);
  58.  
  59.  if (Send && RexxReplyPort && OutRexxMsg)
  60.   SendFirst();
  61. }
  62.  
  63. void ReplyRexxMsg(void)
  64. {
  65.  struct Node *First;
  66.  
  67.  DeleteArgstring(CmdArgstring);
  68.  
  69.  First = RexxList.lh_Head;
  70.  RemHead(&RexxList);
  71.  
  72.  free(First->ln_Name);
  73.  free(First);
  74.  if (RexxList.lh_Head->ln_Succ != NULL)
  75.   SendFirst();
  76. }
  77.  
  78. void LoadFunc(void)
  79. {
  80.  struct Window *wnd;
  81.  char           Buffer[255], Buffer2[255];
  82.  
  83.  set(AP_WinPlot, MUIA_Application_Sleep, TRUE);
  84.  get(WI_WinPlot, MUIA_Window_Window, &wnd);
  85.  if (MUI_AslRequestTags(FileReq,
  86.             ASLFR_DoSaveMode, FALSE,
  87.             ASLFR_Window, wnd,
  88.             ASLFR_TitleText,   "Please select new file to plot",
  89.             ASLFR_DrawersOnly, FALSE,
  90.             TAG_END))
  91.   {
  92.    strcpy(Buffer2, FileReq->fr_Drawer);
  93.    AddPart(Buffer2, FileReq->fr_File, 255);
  94.    sprintf(Buffer, "load \"%s\"", Buffer2);
  95.    SendRexxMsg(Buffer);
  96.   }
  97.  set(AP_WinPlot, MUIA_Application_Sleep, FALSE);
  98. }
  99.  
  100. void SaveFunc(void)
  101. {
  102.  struct Window *wnd;
  103.  char           Buffer[255], Buffer2[255];
  104.  
  105.  set(AP_WinPlot, MUIA_Application_Sleep, TRUE);
  106.  get(WI_WinPlot, MUIA_Window_Window, &wnd);
  107.  if (MUI_AslRequestTags(FileReq,
  108.             ASLFR_DoSaveMode, TRUE,
  109.             ASLFR_Window,      wnd,
  110.             ASLFR_TitleText, "Please select file to save gnuplot state",
  111.             ASLFR_DrawersOnly, FALSE,
  112.             TAG_END))
  113.   {
  114.    strcpy(Buffer2, FileReq->fr_Drawer);
  115.    AddPart(Buffer2, FileReq->fr_File, 255);
  116.    sprintf(Buffer, "save \"%s\"", Buffer2);
  117.    SendRexxMsg(Buffer);
  118.   }
  119.  set(AP_WinPlot, MUIA_Application_Sleep, FALSE);
  120. }
  121.  
  122. void CDFunc(void)
  123. {
  124.  struct Window *wnd;
  125.  char           Buffer[255];
  126.  
  127.  set(AP_WinPlot, MUIA_Application_Sleep, TRUE);
  128.  get(WI_WinPlot, MUIA_Window_Window, &wnd);
  129.  if (MUI_AslRequestTags(FileReq,
  130.             ASLFR_DoSaveMode, FALSE,
  131.             ASLFR_Window,      wnd,
  132.             ASLFR_TitleText,   "Please select new current directory",
  133.             ASLFR_DrawersOnly, TRUE,
  134.             TAG_END))
  135.   {
  136.    sprintf(Buffer, "cd \"%s\"", FileReq->fr_Drawer);
  137.    SendRexxMsg(Buffer);
  138.   }
  139.  set(AP_WinPlot, MUIA_Application_Sleep, FALSE);
  140. }
  141.